package com.kuqi.blog.handler;

import com.kuqi.blog.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author:kuqi
 * @createTime:2021/12/8 21:28
 * @description:统一异常处理
 */


@ControllerAdvice  //对追加了controller注解的方法进行拦截处理，aop实现
public class AllExceptHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody  //返回json数据，不跳转页面
    public Result doException(Exception ex){
        ex.printStackTrace();
        return Result.fail(-999,"系统异常");
    }

}
